package com.express.controller.user;


import com.express.dto.AddressDto;
import com.express.result.Result;
import com.express.service.IAddressesService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author
 * @since 2025-01-25
 */
@Slf4j
@RestController
@RequestMapping("/user/address")
public class AddressController {

    @Autowired
    private IAddressesService addressesService;

    @GetMapping("")
    @ApiOperation("获取地址列表")
    public Result<List<AddressDto>> getAddressList() {
        log.info("获取地址列表");
        return Result.success(addressesService.getAddressList());
    }

    @PostMapping("/add")
    @ApiOperation("新增地址")
    public Result addAddress(@RequestBody AddressDto AddressDto) {
        log.info("新增地址{}", AddressDto);
        addressesService.addAddress(AddressDto);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除地址")
    public Result deleteAddress(@PathVariable Long id) {
        log.info("删除地址:{}", id);
        addressesService.deleteAddress(id);
        return Result.success();
    }

    @PutMapping("/updateAddress")
    @ApiOperation("更新地址")
    public Result updateAddress(@RequestBody AddressDto addressDto) {
        log.info("更新地址：{}", addressDto);
        addressesService.updateAddress(addressDto);
        return Result.success();
    }

    @PostMapping("/{id}/default")
    @ApiOperation("设置默认地址")
    public Result defaultAddress(@PathVariable Long id) {
        log.info("设置默认地址：{}", id);
        addressesService.defaultAddress(id);
        return Result.success();
    }

}
